<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
	<head>
		<meta name="decorator" content="center_common" />
		<script src="${ctxWebStatic }/laydate/laydate.js"></script> 
		<style type="text/css">
		em.error {
			height: 35px;
			display: inline-block;
			vertical-align: middle;
			margin-right: 2px;
			background: url("${ctxWebStatic}/images/error_img.png") no-repeat 0px
				0px;
			padding-left: 24px;
			color: #d3001e;
			font-size: 16px;
			font-family: "微软雅黑";
		}
		</style>
		<script type="text/javascript">
			var subflag = false;//标识提交状态
			var validatorUpdate;
			var validatorAddress;
			var validatorInvoiceCompany;
			var validatorInvoicePerson;
			$(function(){
				validatorUpdate = $("#updateForm").validate({
					onfocusout: function(element) { $(element).valid(); },  
					rules : {
						company : {required : true,companyCheck : true,	rangelength:[5,30]},
						address : {required : true,addressCheck : true,	rangelength:[5,50]},
						account : {required : true,digits : true,rangelength:[5,20]},
						blank : {required : true,blankCheck : true,	rangelength:[4,30]},
						dutyCode : {required : true,dutyCodeCheck:true,	rangelength:[10,30]}
					},
					messages : {
						company : {required : '请输入企业名称',rangelength:'请输入5-30个字符，以汉字或字母开头，可带数字'},
						address : {required : '请输入开票地址',rangelength : '请输入5-50个字符，以汉字开头，可带数字、字母'},
						account : {required : '请输入账户',rangelength : '请输入5-20个数字',digits:'请输入5-20个数字'},
						blank : {required : '请输入开户银行',rangelength : '请输入4-30个字符，以汉字开头，可带数字、字母'},
						dutyCode : {required : '请输入纳税人识别号',rangelength : '请输入10-30个字母或数字'}
					},
					errorContainer: "#messageBox",
					errorPlacement: function(error, element) {
						$("#messageBox").text("输入有误，请先更正。");
						error.insertAfter(element);
					},
					errorElement : "em",
					success:function(lable){
			        	lable.remove(); 
		        	},
				});
				validatorAddress = $("#addressForm").validate({
					onfocusout: function(element) { $(element).valid(); },  
					rules : {
						receive : {required : true,receiveCheck : true,	rangelength:[2,10]},
						phone : {required : true,phoneCheck : true,rangelength:[11,11]},
						address : {required : true,addressCheck : true,	rangelength:[5,50]},
						area : {required : true}
					},
					messages : {
						receive : {required : '请输入收件人',rangelength:'请输入2-10个汉字'},
						phone : {required : '请输入联系方式',rangelength : '格式错误'},
						address : {required : '请输入详细地址',rangelength : '请输入5-50个字符，以汉字开头，可带数字、字母'},
						area : {required : '请选择所在地区'}
					},
					errorContainer: "#messageBox",
					errorPlacement: function(error, element) {
						if (element.is("select")){
							error.insertAfter(element.parents('.tk_selcet'));
						} else {
							error.insertAfter(element);
						}
					},
					errorElement : "em",
					success:function(lable){
			        	lable.remove(); 
		        	},
				});
				validatorInvoiceCompany = $("#InvoiceCompanyForm").validate({
					onfocusout: function(element) { $(element).valid(); },  
					rules : {
						companyName : {required : true,companyCheck : true,rangelength:[5,30]},
						companyDutyCode : {required : true,dutyCodeCheck1 : true,rangelength:[10,30]}
					},
					messages : {
						companyName : {required : '请输入企业名称',rangelength:'请输入5-30个字符，以汉字或字母开头，可带数字'},
						companyDutyCode : {required : '请输入纳税人识别号',rangelength : '请输入10-30个字母或数字'}
					},
					errorContainer: "#messageBox",
					errorPlacement: function(error, element) {
						error.insertAfter(element);
					},
					errorElement : "em",
					success:function(lable){
			        	lable.remove(); 
		        	},
				});
				validatorInvoicePerson = $("#InvoicePersonForm").validate({
					onfocusout: function(element) { $(element).valid(); },  
					rules : {
						invoiceTitle : {required : true,receiveCheck : true,rangelength:[2,10]}
					},
					messages : {
						invoiceTitle : {required : '请输入发票抬头',rangelength : '请输入2-10个汉字'}
					},
					errorContainer: "#messageBox",
					errorPlacement: function(error, element) {
						error.insertAfter(element);
					},
					errorElement : "em",
					success:function(lable){
			        	lable.remove(); 
		        	},
				});
			    jQuery.validator.addMethod("companyCheck", function(value,element, param) { 
					var tel = /^[a-zA-Z\u4e00-\u9fa5][a-zA-Z0-9\u4e00-\u9fa5]*$/;  
				 	return this.optional(element) || (tel.test(value));  
		        }, $.validator.format("请输入5-30个字符，以汉字或字母开头，可带数字")); 
			    
			    jQuery.validator.addMethod("addressCheck", function(value,element, param) { 
					var tel = /^[\u4e00-\u9fa5][a-zA-Z0-9\u4e00-\u9fa5]*$/;  
				 	return this.optional(element) || (tel.test(value));  
		        }, $.validator.format("请输入5-50个字符，以汉字开头，可带数字、字母")); 
			    
			    jQuery.validator.addMethod("blankCheck", function(value,element, param) { 
					var tel = /^[\u4e00-\u9fa5][a-zA-Z0-9\u4e00-\u9fa5]*$/;  
				 	return this.optional(element) || (tel.test(value));  
		        }, $.validator.format("请输入4-30个字符，以汉字开头，可带数字、字母")); 
			    
			    jQuery.validator.addMethod("dutyCodeCheck", function(value,element, param) { 
					var tel = /^[a-zA-Z0-9]*$/;  
				 	return this.optional(element) || (tel.test(value));  
		        }, $.validator.format("请输入10-30个字母或数字")); 
			    
			    jQuery.validator.addMethod("dutyCodeCheck1", function(value,element, param) { 
					var tel = /^[a-zA-Z0-9]*$/;  
				 	return this.optional(element) || (tel.test(value));  
		        }, $.validator.format("请输入10-30个字母或数字")); 
			    
			    jQuery.validator.addMethod("receiveCheck", function(value,element, param) { 
			    	var tel = /^[\u4e00-\u9fa5]*$/;  
				 	return this.optional(element) || (tel.test(value));  
		        }, $.validator.format("请输入2-10个汉字")); 
			    
			    jQuery.validator.addMethod("phoneCheck", function(value,element, param) { 
			    	var tel = /^[1][3,4,5,7,8][0-9]{9}$/;  
				 	return this.optional(element) || (tel.test(value));  
		        }, $.validator.format("格式错误")); 
			    
				$(".parts_search_list i").click(function(){
				    if($(this).hasClass('search_chose_hover')){
					 	$(this).removeClass('search_chose_hover');
					}else{
					 	$(this).addClass('search_chose_hover');
					}
					var vv=$('.parts_search_list i').index($(this));		
					$(".numRadio").find('input').eq(vv).click();
				});
				laydate.render({
				  elem: '#test6',
				  format:'yyyy/MM/dd',
				  range: true,
				  done: function(value, date, endDate){
					  $('#startTime').val(date.year+'-'+date.month+'-'+date.date)
					  $('#endTime').val(endDate.year+'-'+endDate.month+'-'+endDate.date)
					  refreshTransaction();
				  }
				});
				
				$(".js_pos_item input").click(function(){
					$(".js_pos_item").removeClass("pos_strangle");
				});
				$(".pay_detail_tit").click(function(){
					$('#invoiceTypeSelect').change();
					if ($(this).parent().find("i").hasClass("search_chose_hover")) {
						$(this).parent().find("i").removeClass("search_chose_hover");
						$(this).parents(".shopping_car_list").find(".fp_titket_box").hide()
					} else{
						$(this).parent().find("i").addClass("search_chose_hover");
						$(this).parents(".shopping_car_list").find(".fp_titket_box").show()
					}
					var Inputindex=$('.parts_search_list').index($(this));
					$(".numRadio").find('input').eq(Inputindex).click();
				});
				//发票抬头设置
				$(".fp_tab_chose a").click(function(){
					validatorInvoiceCompany.resetForm();
					validatorInvoicePerson.resetForm();
					$(".fp_tab_chose a").removeClass('on_bor');
					$(this).addClass("on_bor");
					showIndex=$(this).index();
					$(this).parents('.fp_tab_box').find(".fp_tab_item").hide();
					$(this).parents('.fp_tab_box').find(".fp_tab_item").eq(showIndex).show();
				});
				//设为默认
				$(".default_box").click(function(){
					if ($(this).parent().find("i").hasClass("search_chose_hover")) {
						$(this).parent().find("i").removeClass("search_chose_hover");
					} else{
						$(this).parent().find("i").addClass("search_chose_hover");
					}
					var Inputindex=$('.parts_search_list').index($(this));
					$(".numRadio").find('input').eq(Inputindex).click();
				});
				
				//省份下拉框选择事件
				$('.provinceSelect').change(function(){
					var provinceId = $(this).val();
					$.ajax({
						url:'${ctxWeb}/address/selectByParent',
						async:false,
						data:{'id':provinceId},
						success:function(result){
							var html = '<option value="">市</option>';
							if(result!=null){
								for(var i = 0;i<result.length;i++){
									var area = result[i];
									if(area.name.length>4){
										var content = area.name.substring(0,3)+'...';
									}else{
										var content = area.name.substring(0,3);
									}
									html += '<option value="'+area.id+'" title="'+area.name+'">'+content+'</option>'
								}
							}
							$('.citySelect').html(html)
							$('.areaSelect').html('<option value="">区</option>')
						}
					})
				})
				//市级下拉框选择事件
				$('.citySelect').change(function(){
					var cityId = $(this).val();
					$.ajax({
						url:'${ctxWeb}/address/selectByParent',
						async:false,
						data:{'id':cityId},
						success:function(result){
							var html = '<option value="">区</option>';
							if(result!=null){
								for(var i = 0;i<result.length;i++){
									var area = result[i];
									if(area.name.length>4){
										var content = area.name.substring(0,3)+'...';
									}else{
										var content = area.name.substring(0,3);
									}
									html += '<option value="'+area.id+'" title="'+area.name+'">'+content+'</option>'
								}
							}
							$('.areaSelect').html(html)
						}
					})
				})
				//新增收貨地址地址保存
				$(".proment_chose_address_save a").click(function(){
					var id = $('.receiveId').val()
					var receive = $('.receiveName').val()
					var phone = $('.receivePhone').val()
					var province = $('.provinceSelect').val()
					var provinceName = $('.provinceSelect').find("option:selected").text()
					var city = $('.citySelect').val()
					var cityName = $('.citySelect').find("option:selected").text()
					var area = $('.areaSelect').val()
					var areaName = $('.areaSelect').find("option:selected").text()
					var address = $('.receiveAddress').val()
					var isDef = 0;
					if($('.address_Bomb_info').find('.default_box').find('.search_chose').hasClass('search_chose_hover')){
						isDef = 1;
					}
					var checkFlag = true;
					if (!$("#addressForm").valid()) {
						checkFlag = false;
					}
					if (!checkFlag) {
						return false;
					}
					$.ajax({
						url:'${ctxWeb}/address/saveAddress',
						async:false,
						data:{
							'id':id,
							'receive':receive,
							'phone':phone,
							'province':province,
							'provinceName':provinceName,
							'city':city,
							'cityName':cityName,
							'area':area,
							'areaName':areaName,
							'address':address,
							'isDef':isDef
						},
						success:function(result){
							refreshInvoiceAddress(result.id,result.receive,result.phone,result.provinceName+result.cityName+result.areaName+result.address);
							$('#proment_new_address').hide();
							if($('.Settlement_address_left').find('figure').size()==2){
								var html = '';
								html += '<figure class="col-xs-3 pad0 Settlement_address_right">'
								html += '<a href="javascript:void(0)" class="js_edit_address" style="padding-top: 20px;" onclick="editAddress()">修改地址</a>'
								html += '</figure>'
								$('.Settlement_address_left').append(html);
							}
						}
					})
				});
				$(".close_page").click(function(){
					$(this).parents('.jd_tk').hide();
				});

				//弹出选择收货地址框
				$(".js_chose_address").click(function(){
					var html = selectAddressByUserId();
					$("#proment_chose_address").find('.chose_set_box').html(html);
					$("#proment_chose_address").show();	
				});
				//弹出选择发票邮寄地址框
				$("#chose_invoice_address").click(function(){
					var html = selectAddressByUserId();
					$("#proment_chose_invoice_address").find('.chose_set_box').html(html);
					$("#proment_chose_invoice_address").show();	
				});
				//弹出选择开票信息框
				$("#choseInvoice").click(function(){
					var html = selectInvoiceByUserId();
					$("#proment_chose_invoice").find('.chose_set_box').html(html);
					$("#proment_chose_invoice").show();	
				});
				$(".chose_set_box").on('click','.chose_address_info',function(){
					$(this).parent().find(".chose_address_info").removeClass("chose_address_info_hover");
					$(this).addClass("chose_address_info_hover");	
				});
				//选择发票邮寄地址后保存
				$("#proment_chose_invoice_address .shopping_car_confirm a").click(function(){
					$("#proment_chose_invoice_address").hide();
					var chose_box = $('#proment_chose_invoice_address').find('.chose_set_box').find('.chose_address_info_hover');
					var chose_address_id = $(chose_box).find('.chose_address_info_id').text();
					var chose_address_receive = $(chose_box).find('.chose_address_info_receive').text();
					var chose_address_phone = $(chose_box).find('.chose_address_info_phone').text();
					var chose_address_address = $(chose_box).find('.chose_address_info_address').text();
					refreshInvoiceAddress(chose_address_id,chose_address_receive,chose_address_phone,chose_address_address);
				});
				//交易历史关闭
				$("#proment_new_Credit .shopping_car_confirm a").click(function(){
					$("#proment_new_Credit").hide();
				});
				//选择开票信息后保存
				$("#proment_chose_invoice .shopping_car_confirm a").click(function(){
					$("#proment_chose_invoice").hide();
					var chose_box = $('#proment_chose_invoice').find('.chose_set_box').find('.chose_address_info_hover');
					var chose_invoice_id = $(chose_box).find('.chose_invoice_id').text();
					var chose_invoice_company = $(chose_box).find('.chose_invoice_company').text();
					var chose_invoice_account = $(chose_box).find('.chose_invoice_account').text();
					var chose_invoice_blank = $(chose_box).find('.chose_invoice_blank').text();
					var chose_invoice_address = $(chose_box).find('.chose_invoice_address').text();
					var chose_invoice_dutyCode = $(chose_box).find('.chose_invoice_dutyCode').text();
					var chose_invoice_isDef = $(chose_box).find('.chose_invoice_isDef').text();
					refreshInvoice(chose_invoice_id,chose_invoice_company,chose_invoice_address,chose_invoice_account,chose_invoice_blank,chose_invoice_dutyCode,chose_invoice_isDef)
				});
				$(".pay_details").click(function(){
					refreshTransaction()
					$("#proment_new_Credit").show();	
				});
				$('#transactionTypeSelect').change(function(){
					refreshTransaction();
				})
				//打开新增地址框
				$(".js_new_address").click(function(){
					validatorAddress.resetForm();  
					var flag = true;
					$.ajax({
						url:'${ctxWeb}/address/selectByUserId',
						async:false,
						success:function(result){
							if(result!=null){
								if(!(result.length<10)){
									$('#checkShowBoxSpan').text('最多只能添加10个地址，不能继续添加新地址');
									$('#checkShowBox').show();
									flag = false;
								}
							}
						}
					})
					if(!flag){
						return;
					}
					$('.receiveName').val('');
					$('.receivePhone').val('')
					$('.provinceSelect').val('')
					$('.citySelect').val('')
					$('.areaSelect').val('')
					$('.receiveAddress').val('')
					$('.default_box').find('.search_chose').removeClass('search_chose_hover')
					$.ajax({
						url:'${ctxWeb}/address/getProvince',
						async:false,
						success:function(result){
							var html = '<option value="">省</option>';
							if(result!=null){
								for(var i = 0;i<result.length;i++){
									var area = result[i];
									if(area.name.length>4){
										var content = area.name.substring(0,3)+'...';
									}else{
										var content = area.name.substring(0,3);
									}
									html += '<option value="'+area.id+'" title="'+area.name+'">'+content+'</option>'
								}
							}
							$('.provinceSelect').html(html)
						}
					})
					$("#proment_new_address").show();	
				});
				//选择发票类型
				$('#invoiceTypeSelect').change(function(){
					var invoiceType = $('#invoiceTypeSelect').val();
					if("1"==invoiceType){//选择专用
						//获取默认
						$.ajax({
							url:'${ctxWeb}/webInvoice/getDefInvoice',
							async:false,
							success:function(result){
								if(result!=null){
									refreshInvoice(result.id,result.company,result.address,result.account,result.blank,result.dutyCode);
								}
							}
						})
						$('#commonInvoive').hide();
						$('#specialInvoive').show();
					}else{//选择普通
						$('#commonInvoive').show();
						$('#specialInvoive').hide();
					}
					
				})
			    /* pc端订单状态切换*/
			  	tabOrder($(".ord-list-box .order-state-item"),$(".order-data .order-list"));
				/* 移动端订单状态切换 */
				tabOrder($(".ph-order-tab .order-item"),$(".ph-ord-list"));
				/* 切换公共方法 */
				function tabOrder(obj,oList){
					obj.on("click", function(){
						var _index = $(this).index();
						$(this).addClass("active").siblings().removeClass("active");
						oList.hide().first().show();
						oList.eq(_index).show().siblings().hide();
					})
				}
			})
			//弹出新增窗口
			function showAdd() {
				var invoiceSize = 0;
				$.ajax({
					url:'${ctxWeb}/webInvoice/selectByUserId',
					async:false,
					success:function(result){
						invoiceSize = result.length;
					}
				})
				if(!(invoiceSize<10)){
					$('#checkShowBoxSpan').text('最多只能添加10个发票信息，不能继续添加新发票信息');
					$('#checkShowBox').show();
					return;
				}
				validatorUpdate.resetForm();
				Modify = false;//标识为非修改状态
				invoiceId = "";
				$("#invoiceId").val("");
				$("#company").val("");
				$("#address").val("");
				$("#account").val("");
				$("#blank").val("");
				$("#dutyCode").val("");
				if ($("#proment_new_fptitket").find("i").hasClass("search_chose_hover")) {
					$("#proment_new_fptitket").find("i").removeClass(
							"search_chose_hover");
				}
				$("#isDef").prop("checked", false);
				$("#proment_new_fptitket").show();
			}
			//弹出修改窗口
			function showModify() {
				validatorUpdate.resetForm();
				invoiceId = $('.special_invoice_id').text();
				company = $('.special_invoice_company').text();
				address = $('.special_invoice_address').text();
				account = $('.special_invoice_account').text();
				blank = $('.special_invoice_blank').text();
				dutyCode = $('.special_invoice_code').text();
				isDef = $('.special_invoice_isDef').text();
				if(invoiceId==''){
					$('#checkShowBoxSpan').text('请先选择开票信息');
					$('#checkShowBox').show();
					return false;
				}
				$("#invoiceId").val(invoiceId);
				$("#company").val(company);
				$("#address").val(address);
				$("#account").val(account);
				$("#blank").val(blank);
				$("#dutyCode").val(dutyCode);
				if (isDef == 1) {
					if ($("#proment_new_fptitket").find("i").hasClass("search_chose_hover")) {
					} else {
						$("#proment_new_fptitket").find("i").addClass("search_chose_hover");
					}
					Modify = true;
					$("#isDef").prop("checked", true);
		
				} else {
					if ($(".default_box").parent().find("i").hasClass("search_chose_hover")) {
						$(".default_box").parent().find("i").removeClass("search_chose_hover");
					}
					Modify = false;
					$("#isDef").prop("checked", false);
				}
				$("#proment_new_fptitket").show();
			}
			//新增
			function sub() {
				var checkFlag = true;
				if (!$("#updateForm").valid()) {
					checkFlag = false;
				}
				if (!checkFlag) {
					return false;
				}
				$.ajax({
					url:"${ctxWeb}/webInvoice/saveReturn",
					data:$("#updateForm").serialize() ,
					async:false,
					success:function(result){
						if(result!=null){
							refreshInvoice(result.id,result.company,result.address,result.account,result.blank,result.dutyCode,result.isDef);
						}
						$('#proment_new_fptitket').hide();
					}
				});
			}
			function refreshTransaction(){
				var type = $('#transactionTypeSelect').val();
				var startTime = $('#startTime').val();
				var endTime = $('#endTime').val();
				var html = ''
				$.ajax({
					url:'${ctxWeb}/home/getMyTransactionHistory',
					data:{
						'type':type,
						'startTime':startTime,
						'endTime':endTime
					},
					type:"POST",
					async:false,
					success:function(result){
						if(result!=null){
							for(var i = 0;i<result.length;i++){
								var transaction = result[i];
								html += '<tr>';
								html += '<td>'+transaction.code+'</td>';
								html += '<td>'+transaction.typeName+'</td>';
								html += '<td>'+transaction.money+'</td>';
								html += '<td>'+transaction.createDate+'</td>';
								if(transaction.remarks==null){
									html += '<td></td>';
								}else{
									html += '<td>'+transaction.remarks+'</td>';
								}
								html += '</tr>';
							}
						}
						$('#transactionList').html(html)
					}
				})
			}
			function selectAddressByUserId(){
				var html = '';
				 $.ajax({
					url:'${ctxWeb}/address/selectByUserId',
					async:false,
					success:function(result){
						if(result!=null){
							for(var i = 0;i<result.length;i++){
								var address = result[i];
								if(address.isDef==0){
									html += '<div class="chose_address_info address_Bomb_info clearfix">';
								}else{
									html += '<div class="chose_address_info address_Bomb_info chose_address_info_hover clearfix">';
								}
								html += '<figure class="Settlement_address_msg">';
								html += '<p class="chose_address_info_id hide">'+address.id +'</p>';
								html += '<p><em>收件人&nbsp;&nbsp;&nbsp;&nbsp;：</em><span class="chose_address_info_receive">'+address.receive +'</span></p>';
								html += '<p><em>联系方式  ：</em><span class="chose_address_info_phone">'+address.phone +'</span></p>';
								html += '<p><em>收货地址  ：</em><span class="chose_address_info_address">'+address.provinceName+address.cityName+address.areaName+address.address+'</span></p>';
								html += '<p class="set_address">当前默认</p></figure></div>';
							}
						}
					}
				})
				return html;
			}
			//获取当前用户的所有开票信息
			function selectInvoiceByUserId(){
				var html = '';
				 $.ajax({
					url:'${ctxWeb}/webInvoice/selectByUserId',
					async:false,
					success:function(result){
						if(result!=null){
							for(var i = 0;i<result.length;i++){
								var invoice = result[i];
								if(invoice.isDef==0){
									html += '<div class="chose_address_info address_Bomb_info clearfix">';
								}else{
									html += '<div class="chose_address_info address_Bomb_info chose_address_info_hover clearfix">';
								}
								html += '<figure class="Settlement_address_msg">';
								html += '<p class="chose_invoice_id hide">'+invoice.id +'</p>';
								html += '<p><em>企业名称&nbsp;&nbsp;&nbsp;&nbsp;：</em><span class="chose_invoice_company">'+invoice.company +'</span></p>';
								html += '<p><em>开票地址  ：</em><span class="chose_invoice_address">'+invoice.address+'</span></p>';
								html += '<p><em>账号  ：</em><span class="chose_invoice_account">'+invoice.account +'</span></p>';
								html += '<p><em>开户行  ：</em><span class="chose_invoice_blank">'+invoice.blank +'</span></p>';
								html += '<p><em>纳税人识别号  ：</em><span class="chose_invoice_dutyCode">'+invoice.dutyCode +'</span></p>';
								html += '<span class="chose_invoice_isDef hide">'+invoice.isDef +'</span>';
								html += '<p class="set_address">当前默认</p></figure></div>';
							}
						}
					}
				})
				return html;
			}
			//修改地址
			function editAddress(){
				$.ajax({
					url:'${ctxWeb}/address/getProvince',
					async:false,
					success:function(result){
						var html = '<option value="">省</option>';
						if(result!=null){
							for(var i = 0;i<result.length;i++){
								var area = result[i];
								if(area.name.length>4){
									var content = area.name.substring(0,3)+'...';
								}else{
									var content = area.name.substring(0,3);
								}
								html += '<option value="'+area.id+'" title="'+area.name+'">'+content+'</option>'
							}
						}
						$('.provinceSelect').html(html)
					}
				})
				var addressId = $('#choseAddressId').val();
				if(addressId!=null && addressId!=''){
					$.ajax({
						url:'${ctxWeb}/address/getAddress',
						data:{'id':addressId},
						async:false,
						success:function(result){
							$('.receiveId').val(result.id)
							$('.receiveName').val(result.receive)
							$('.receivePhone').val(result.phone)
							$('.receiveAddress').val(result.address)
							$(".provinceSelect").find("option[value='"+result.province+"']").attr("selected",true);
							$(".provinceSelect").change()
							$(".citySelect").find("option[value='"+result.city+"']").attr("selected",true);
							$(".citySelect").change()
							$(".areaSelect").find("option[value='"+result.area+"']").attr("selected",true);
							if(result.isDef=='1'){
								$('.default_box').find('.search_chose').addClass('search_chose_hover');
							}else{
								$('.default_box').find('.search_chose').removeClass('search_chose_hover');
							}
							$("#proment_new_address").show();	
						}
					})
				}
			}
			//刷新当前选择发票邮寄地址
			function refreshInvoiceAddress(chose_address_id,chose_address_receive,chose_address_phone,chose_address_address){
				var Settlement_address = $('.fp_address_msg');
				$(Settlement_address).find('#choseAddressId').val(chose_address_id);
				$(Settlement_address).find('.invoice_receive_name').text(chose_address_receive);
				$(Settlement_address).find('.invoice_receive_phone').text(chose_address_phone);
				$(Settlement_address).find('.invoice_receive_address').text(chose_address_address);
			}
			//刷新当前默认开票
			function refreshInvoice(special_invoice_id,special_invoice_company,special_invoice_address,special_invoice_account,special_invoice_blank,special_invoice_code,special_invoice_isDef){
				var special_invoice = $('.special_invoice');
				$(special_invoice).find('.special_invoice_id').text(special_invoice_id);
				$(special_invoice).find('.special_invoice_company').text(special_invoice_company);
				$(special_invoice).find('.special_invoice_address').text(special_invoice_address);
				$(special_invoice).find('.special_invoice_account').text(special_invoice_account);
				$(special_invoice).find('.special_invoice_blank').text(special_invoice_blank);
				$(special_invoice).find('.special_invoice_code').text(special_invoice_code);
				$(special_invoice).find('.special_invoice_isDef').text(special_invoice_isDef);
			}
			//点击还款
			function returnMoneyFunc(){
				var returnMoney = $('#returnMoney').val();
				var isInvoice = $('.pay_detail_tit').find('.search_chose').hasClass('search_chose_hover')
				if(returnMoney==''){
					$('#checkShowBoxSpan').text('请输入还款金额');
					$('#checkShowBox').show();
					return false;
				}
				$('#money').val(returnMoney);
				//勾选了需要发票
				if(isInvoice){
					$('#isInvoice').val("1");
					var invoiceType = $('#invoiceTypeSelect').val();
					$('#invoiceTypeInput').val(invoiceType);
					var invoice_address_id = $('#choseAddressId').val();
					if(invoice_address_id==''){
						$('#checkShowBoxSpan').text('请选择发票邮寄地址');
				   		$('#checkShowBox').show();
				   		return false;
					}
					if(invoiceType=="1"){//增值税专用发票
						if($('.special_invoice_id').text()==''){
							$('#checkShowBoxSpan').text('请选择开票信息');
					   		$('#checkShowBox').show();
					   		return false;
						}
						$('#companyInput').val($('.special_invoice_company').text());
						$('#addressInput').val($('.special_invoice_address').text());
						$('#accountInput').val($('.special_invoice_account').text());
						$('#blankInput').val($('.special_invoice_blank').text());
						$('#dutyCodeInput').val($('.special_invoice_code').text());
						$('#invoiceTitleInput').val($('.special_invoice_company').text());
					}else{//增值税普通发票
						var type = $('#commonInvoive').find('.on_bor').attr('type');
						if(type=="1"){//单位
							$('#companyInput').val($('#companyName').val());
							$('#dutyCodeInput').val($('#companyDutyCode').val());
							$('#invoiceTitleInput').val($('#companyName').val());
							if($("#InvoiceCompanyForm").valid()){
								$('#returnMoneyForm').submit();
							}else{
								$('#checkShowBoxSpan').text('请输入开票信息');
						   		$('#checkShowBox').show();
						   		return false;
							}
						}else{
							var title = $('#invoiceTitle').val();
							$('#invoiceTitleInput').val(title);
							if($("#InvoicePersonForm").valid()){
								$('#returnMoneyForm').submit();
							}else{
								$('#checkShowBoxSpan').text('请输入开票信息');
						   		$('#checkShowBox').show();
						   		return false;
							}
						}
					}
					$('#invoiceReceiveName').val($('.invoice_receive_name').text());
					$('#invoiceReceivePhone').val($('.invoice_receive_phone').text());
					$('#invoiceReceiveAddress').val($('.invoice_receive_address').text());
				}else{
					$('#isInvoice').val("0");
				}
				$('#returnMoneyForm').submit();
			}
    	</script>
	</head>
	<body>
	<!-- 右边部分 -->
	<div class="col-sm-10 pad20 pad_10">
		<div class="Credit_right">
		<c:if test="${user.userType=='1' }">
			<div class="col-sm-10 pad20 pad_10">
				<div class="Credit_right">
					<!--企业信息-->
					<div class="goods_detail_info_box mar_16 clearfix">
						<h3>
							<span>信用额度</span>

						</h3>
						<div class="company_info_none">
							<p>
								暂无信用额度，升级企业会员即可获得信用额度。 <a href="${ctxWeb}/register/toAssociator">升级企业会员</a>
							</p>
						</div>
					</div>
					<!--企业信息结束-->
				</div>
			</div>
		</c:if>
		<c:if test="${user.userType=='2' }">
			<!--企业额度信息-->
			<div class="goods_detail_info_box mar_16 clearfix">
				<h3><span>企业/额度信息</span></h3>
				<!--信用表格信息-->
				<div class="Credit_table_box">
					<div class="logistic_table  col-xs-11 clearfix">
						<table class="table table-bordered">
							 <caption>公司名称：${user.company }</caption>
						    <thead>
						      <tr>
						        <th>可用额度</th>
						        <th>总额度</th>
						        <th>账户状态</th>
						        <th>交易记录</th>
						      </tr>
						    </thead>
						    <tbody>
						      <tr>
						        <td class="able_Credit">¥${myCredit.money+myCredit.rechargeMoney-myCredit.useMoney }</td>
						        <td>¥${myCredit.money }</td>
						        <td>${fns:getDictLabel(myCredit.status, 'credit_status', '')}</td>
						        <td class="pay_details">交易明细</td>
						      </tr>
						    </tbody>
						  </table>
					</div>
				</div>
				<!--信用表格信息结束-->
			</div>	
			<!--企业额度信息结束-->
			<!--额度信息-->
			<div class="goods_detail_info_box mar_16 clearfix">
				<h3><span>额度还款</span></h3>
				<!--额度还款信息-->
				<div class="Quota_box">
					<figure class="Quota_box_title">
							<label>还款金额：</label>
							<input type="text" id="returnMoney" placeholder="请输入还款金额"/>
							<button class="submit_btn" onclick="returnMoneyFunc()">提交</button>
					</figure>
					<!--发票信息-->
					<div class="shopping_car_list">
						<h3 class="pay_detail_tit fp_mar" id="payDetailInvoice">
							<i class="search_chose"></i>
							需要发票
						</h3>
						<div class='numRadio' style="display: none;">
							<input type='checkbox' name='needInvoice' value='1' />
						</div>
						<div class="fp_titket_box col-sm-offset-1" style="display: none;">
							<div class="form-group clearfix">
							    <label  class="col-sm-2 col-xs-5 fp_lable control-label ">
							    	发票类型：
							    </label>
							    <div class="col-sm-5 col-xs-7 fp_input_left pad0">
							      	<select class="form-control hy" id="invoiceTypeSelect">
								      <option value="2" selected="selected">增值税普通发票</option>
								      <option value="1">增值税专用发票</option>
								    </select>
							    </div>
							</div>
							<!--发票切换-->
							<!-- 增值税普通发票  -->
							<div class="fp_tab_box" id="commonInvoive">
								<div class="form-group clearfix">
								    <label  class="col-sm-2 col-xs-5 fp_lable control-label ">
								    	发票抬头：
								    </label>
								    <div class="col-sm-5 col-xs-7 fp_tab_chose pad0">
								      	<a href="javascript:void(0)" class="on_bor" type="1">单位</a>
								      	<a href="javascript:void(0)" type="2">个人</a>
								    </div>
								</div>
								<div class="fp_tab_yab">
									<!--单位信息-->
									<form action="" id="InvoiceCompanyForm" method="post">
									<div class="fp_tab_item">
										<div class="form-group clearfix">
											<label  class="col-sm-2 col-xs-5 fp_lable control-label ">
										    	企业名称：
										    </label>
										    <div class="col-sm-5 col-xs-7  pad0">
										      	<input type="text" id="companyName" name="companyName" class="form-control" placeholder="请输入营业执照上企业名称">
										    </div>
										</div>
										<div class="form-group clearfix">
											<label  class="col-sm-2 col-xs-5 fp_lable control-label ">
										    	纳税人识别号：
										    </label>
										    <div class="col-sm-5 col-xs-7 pad0">
										      	<input type="text" id="companyDutyCode" name="companyDutyCode" class="form-control" placeholder="请输入纳税人识别号">
										    </div>
										</div>
									</div>
									</form>
									<!--单位信息结束-->
									<!--个人信息-->
									<form action="" id="InvoicePersonForm" method="post">
									<div class="fp_tab_item" style="display: none;">
										<div class="form-group clearfix">
											<label  class="col-sm-2 col-xs-5 fp_lable control-label ">
										    	发票抬头：
										    </label>
										    <div class="col-sm-5 col-xs-7 pad0">
										      	<input type="text" id="invoiceTitle" name="invoiceTitle" class="form-control" placeholder="请输入发票抬头">
										    </div>
										</div>
									</div>
									</form>
									<!--个人信息结束-->
								</div>
							</div>
							<!-- 增值税专用发票  -->
							<div class="fp_tab_box" style="display:none" id="specialInvoive">
								<div class="fp_tab_yab">
									<!--单位信息-->
									<div class="fp_tab_item special_invoice">
										<p class="line40 special_invoice_id hide"></p>
										<div class="form-group clearfix">
											<label  class="col-sm-2 col-xs-5 fp_lable control-label ">
										    	企业名称：
										    </label>
										    <div class="col-sm-5 col-xs-7 pad0">
										      	<p class="line40 special_invoice_company"></p>
										    </div>
										</div>
										<div class="form-group clearfix">
											<label  class="col-sm-2 col-xs-5 fp_lable control-label ">
										    	开票地址：
										    </label>
										    <div class="col-sm-5 col-xs-7 pad0">
										      	<p class="line40 special_invoice_address"></p>
										    </div>
										</div>
										<div class="form-group clearfix">
											<label  class="col-sm-2 col-xs-5 fp_lable control-label ">
										    	账号：
										    </label>
										    <div class="col-sm-5 col-xs-7 pad0">
										      	<p class="line40 special_invoice_account"></p>
										    </div>
										</div>
										<div class="form-group clearfix">
											<label  class="col-sm-2 col-xs-5 fp_lable control-label ">
										    	开户行：
										    </label>
										    <div class="col-sm-5 col-xs-7 pad0">
										      	<p class="line40 special_invoice_blank"></p>
										    </div>
										</div>
										<div class="form-group clearfix">
											<label  class="col-sm-2 col-xs-5 fp_lable control-label ">
										    	纳税人识别号：
										    </label>
										    <div class="col-sm-5 col-xs-7 pad0">
										      	<p class="line40 special_invoice_code"></p>
										    </div>
										</div>
								      	<p class="line40 special_invoice_isDef hide"></p>
										<div class="fp_address col-sm-offset-2 col-xs-offset-5">
											<a href="javascript:void(0)" class="chose_address" id="choseInvoice">选择开票信息</a>
											<a href="javascript:void(0)" class="chose_address" onclick="showAdd()">新增开票信息</a>
											<a href="javascript:void(0)" class="chose_address" onclick="showModify()">修改开票信息</a>
										</div>
									</div>
									<!--单位信息结束-->
								</div>
							</div>
							<!--发票切换结束-->
							<div class="form-group fp_address_msg clearfix">
								<em  class="col-sm-2 col-xs-5 pad0">
							    	发票邮寄地址：
							    </em>
							    <div class="col-sm-5 col-xs-7 pad0">
							   	 	<input type="hidden" value="${defAddress.id }" id="choseAddressId">	
									<p>
							      		<span class="invoice_receive_name">${defAddress.receive }</span>
							      		<span class="invoice_receive_phone">${defAddress.phone }</span>
							      	</p>
							      	<p class="invoice_receive_address">${defAddress.provinceName }${defAddress.cityName }${defAddress.areaName }${defAddress.address }</p>
							    </div>
							</div>
							<div class="fp_address col-sm-offset-2 col-xs-offset-5">
								<a href="javascript:void(0)" class="chose_address" id="chose_invoice_address">选择地址</a>
								<a href="javascript:void(0)" class="chose_address js_new_address">新增地址</a>
								<a href="javascript:void(0)" class="chose_address" onclick="editAddress()">修改地址</a>
							</div>
						</div>
					</div>
					<!--发票信息结束-->
				</div>
				<!--额度还款信息结束-->
			</div>
			<!--额度信息结束-->
		</div> 
		</c:if>
	</div>
	<!-- 右边部分 end-->
	<!--主题内容结束-->
	
	<!---------弹框-------->
	<!--交易明细弹框-->
	<div class="jd_tk" id="proment_new_Credit" style="display: none;">
		<div class="address_Bomb">
			<h3 class="address_Bomb_title mar_b0 clearfix">
				交易明细
				<span class="close_page">
					<img src="${ctxWebStatic }/images/close.png" alt="" />
				</span>
			</h3>
			<div class="Credit_pay_box mar_b0 clearfix">
				<div class="Transaction_box">
					<form:form  modelAttribute="webTransactionHistory">
					<div class="Transaction_title clearfix">
						<p class="col-sm-7 Transaction_time pad_r0">
							<label>日期：</label>
							<input type="hidden" id="startTime">
							<input type="hidden" id="endTime">
							<input type="text" class="demo-input hy" value="" id="test6">
						</p>
						<p class="col-sm-5 Transaction_type pad_r0">
							<label>交易类型：</label>
							<form:select path="type" class="hy" id="transactionTypeSelect">
								<form:option value="" label="请选择"/>
								<form:options items="${fns:getDictList('transaction_type')}" htmlEscape="false" itemValue="value" itemLabel="label"/>
							</form:select>
						</p>
					</div>
					</form:form>
					<!--表格-->
					<div class="logistic_table Transaction_table  clearfix">
						<table class="table table-bordered">
						    <thead>
						      <tr>
						        <th>交易编号</th>
						        <th>交易类型</th>
						        <th>金额</th>
						        <th>日期</th>
						        <th>备注</th>
						      </tr>
						    </thead>
						    <tbody id="transactionList">
						    
						    </tbody>
						  </table>
					</div>
					<!--表格结束-->
				</div>
			</div>
			<div class=" shopping_car_price shopping_car_confirm">
				<a href="javascript:void(0)">确认</a>
			</div>
		</div>
	</div>
	<!--交易明细弹框结束-->
	<!--新增编辑地址弹框-->
	<div class="jd_tk" id="proment_new_address" style="display: none;">
		<form action="" id="addressForm" method="post">
		<input type="hidden" id="id" name="id" value="" />
		<div class="address_Bomb">
			<h3 class="address_Bomb_title">
				新增地址
				<span class="close_page">
					<img src="${ctxWebStatic }/images/close.png" alt="" />
				</span>
			</h3>
			<div class="address_Bomb_info clearfix">
				<div class="address_Bomb_left col-sm-9 clearfix">
					<input type="hidden" class="receiveId">
					<figure class="form-group clearfix">
						<label  class="col-sm-3 col-xs-5 fp_lable control-label ">
					    	收件人：
					    </label>
					    <div class="col-sm-8 col-xs-7 pad0">
					      	<input type="text" class="form-control receiveName" name="receive" placeholder="请填写收件人">
					    </div>
					</figure>
					<figure class="form-group clearfix">
						<label  class="col-sm-3 col-xs-5 fp_lable control-label ">
					    	联系方式：
					    </label>
					    <div class="col-sm-8 col-xs-7 pad0">
					      	<input type="text" class="form-control receivePhone" name="phone" placeholder="请填写联系方式">
					    </div>
					</figure>
					<figure class="form-group clearfix">
						<label  class="col-sm-3 col-xs-5 fp_lable control-label ">
					    	所在地区：
					    </label>
					    <div class="col-sm-8 col-xs-7 pad0">
					      	<div class="tk_selcet"><!-- container -->									  	
								<select class="hy col-xs-12 col-sm-3 provinceSelect" name="province">
									<option value="">省</option>
								</select>
								<select class="hy col-xs-12 col-sm-3 citySelect" name="city">
									<option value="">市</option>
								</select>
								<select class="hy col-xs-12 col-sm-3 areaSelect" name="area">
									<option value="">区</option>
								</select>
							</div>
					    </div>
					</figure>
					<figure class="form-group clearfix">
						<label  class="col-sm-3 col-xs-5 fp_lable control-label ">
					    	详细地址：
					    </label>
					    <div class="col-sm-8 col-xs-7 pad0">
					      	<input type="text" class="form-control receiveAddress" name="address" placeholder="请填写详细地址">
					    </div>
					</figure>
				</div>
				<div class="col-sm-3 default_left">
					<div class="default_box">
						<i class="search_chose"></i>
						<span>设为默认地址</span>
					</div>
					<div class='numRadio' style="display: none;">
						<input type='checkbox' name='isDef' value='设为默认地址' />
					</div>
				</div>
			</div>
			<div class=" shopping_car_price  proment_chose_address_save">
				<a href="javascript:void(0)">确认</a>
			</div>
		</div>
		</form>
	</div>
	<!--新增修改地址弹框结束-->
	<!--选择地址弹框-->
	<div class="jd_tk" id="proment_chose_address" style="display: none;">
		<div class="address_Bomb">
			<h3 class="address_Bomb_title">
				选择地址
				<span class="close_page">
					<img src="${ctxWebStatic }/images/close.png" alt="" />
				</span>
			</h3>
			<div class="chose_set_box">
			
			</div>
			<div class=" shopping_car_price shopping_car_confirm">
				<a href="javascript:void(0)">确认</a>
			</div>
		</div>
	</div>
	<!--选择地址弹框结束-->
	<!--发票弹框-->
	<div class="jd_tk" id="proment_new_fptitket" style="display: none;">
		<form action="${ctxWeb}/webInvoice/save" id="updateForm" method="post">
			<input type="hidden" id="invoiceId" name="id" value="" />
			<div class="address_Bomb">
				<h3 class="address_Bomb_title">
					发票信息 <span class="close_page"> <img
						src="${ctxWebStatic}/images/close.png" alt="" />
					</span>
				</h3>
				<div class="address_Bomb_info clearfix">
					<div class="address_Bomb_left col-sm-9 clearfix">
						<figure class="form-group clearfix">
							<label class="col-sm-3 col-xs-5 fp_lable control-label ">
								企业名称： </label>
							<div class="col-sm-8 col-xs-7 pad0">
								<input type="text" class="form-control" id="company"
									name="company" placeholder="请输入企业名称">
							</div>
						</figure>

						<figure class="form-group clearfix">
							<label class="col-sm-3 col-xs-5 fp_lable control-label ">
								开票地址： </label>
							<div class="col-sm-8 col-xs-7 pad0">
								<div data-toggle="distpicker" class="tk_selcet">
									<!-- container -->
									<input type="text" class="form-control" id="address"
										name="address" placeholder="请输入开票地址">
								</div>
							</div>
						</figure>
						<figure class="form-group clearfix">
							<label class="col-sm-3 col-xs-5 fp_lable control-label ">
								账户： </label>
							<div class="col-sm-8 col-xs-7 pad0">
								<input type="text" class="form-control" id="account"
									name="account" placeholder="请输入账户">
							</div>
						</figure>
						<figure class="form-group clearfix">
							<label class="col-sm-3 col-xs-5 fp_lable control-label ">
								开户银行： </label>
							<div class="col-sm-8 col-xs-7 pad0">
								<input type="text" class="form-control" id="blank" name="blank"
									placeholder="请输入开户银行">
							</div>
						</figure>
						<figure class="form-group clearfix">
							<label class="col-sm-3 col-xs-5 fp_lable control-label ">
								纳税人识别号： </label>
							<div class="col-sm-8 col-xs-7 pad0">
								<input type="text" class="form-control" id="dutyCode"
									name="dutyCode" placeholder="请输入纳税热识别号">
							</div>
						</figure>
					</div>
					<div class="col-sm-3 default_left">
						<div class="default_box">
							<i class="search_chose"></i> <span>设为默认地址</span>
						</div>
						<div class='numRadio' style="display: none;">
							<input type='checkbox' name='isDef' id="isDef" value='1' />
						</div>
					</div>
				</div>
				<div class=" shopping_car_price shopping_car_confirm">
					<a href="javascript:void(0)" onclick="sub()">确认</a>
				</div>
			</div>
		</form>
	</div>
	<!--发票弹框结束-->
	<!--选择发票邮寄地址弹框-->
	<div class="jd_tk" id="proment_chose_invoice_address" style="display: none;">
		<div class="address_Bomb">
			<h3 class="address_Bomb_title">
				选择地址
				<span class="close_page">
					<img src="${ctxWebStatic }/images/close.png" alt="" />
				</span>
			</h3>
			<div class="chose_set_box">
			
			</div>
			<div class=" shopping_car_price shopping_car_confirm">
				<a href="javascript:void(0)">确认</a>
			</div>
		</div>
	</div>
	<!--选择开票信息弹框-->
	<div class="jd_tk" id="proment_chose_invoice" style="display: none;">
		<div class="address_Bomb">
			<h3 class="address_Bomb_title">
				选择开票信息
				<span class="close_page">
					<img src="${ctxWebStatic }/images/close.png" alt="" />
				</span>
			</h3>
			<div class="chose_set_box">
			
			</div>
			<div class=" shopping_car_price shopping_car_confirm">
				<a href="javascript:void(0)">确认</a>
			</div>
		</div>
	</div>
	<!--新增编辑地址弹框-->
	<form action="${ctxWeb}/home/returnMoney" id="returnMoneyForm" method="post">
		<!-- 还款   -->
		<input name="money" id="money" type="hidden">
		<input name="isInvoice" id="isInvoice" type="hidden">
		
		<!-- 发票   -->
		<input name="receiveName" id="invoiceReceiveName" type="hidden">
		<input name="receivePhone" id="invoiceReceivePhone" type="hidden">
		<input name="receiveAddress" id="invoiceReceiveAddress" type="hidden">
		<input name="invoiceType" id="invoiceTypeInput" type="hidden">
		<input name="account" id="accountInput" type="hidden">
		<input name="blank" id="blankInput" type="hidden">
		<input name="dutyCode" id="dutyCodeInput" type="hidden">
		<input name="company" id="companyInput" type="hidden">
		<input name="address" id="addressInput" type="hidden">
		<input name="invoiceTitle" id="invoiceTitleInput" type="hidden">
	</form>
	</body>
</html>
